package com.settlement.system.controller;

import com.settlement.system.common.annotation.PreventDuplicateSubmit;
import com.settlement.system.common.result.Result;
import com.settlement.system.model.form.ColumnAppendForm;
import com.settlement.system.model.form.ColumnMatchForm;
import com.settlement.system.service.SysColumnAppendService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 * 账单项目字段累加配置 前端控制器
 * </p>
 *
 * @author huangrensen
 * @since 2023-09-20
 */
@RestController
@RequestMapping("/api/v1/columnAppend")
@RequiredArgsConstructor
public class SysColumnAppendController {

    private final SysColumnAppendService sysColumnAppendService;

    @Operation(summary = "保存账单项目字段累加配置", security = {@SecurityRequirement(name = "Authorization")})
    @PostMapping
    @PreAuthorize("@ss.hasPerm('sys:columnAppend:save')")
    @PreventDuplicateSubmit
    public Result<?> saveColumnMatch(@Valid @RequestBody ColumnAppendForm columnMatchForm) {
        return Result.success(sysColumnAppendService.saveForm(columnMatchForm));
    }

    @Operation(summary = "删除账单项目字段累加配置", security = {@SecurityRequirement(name = "Authorization")})
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('sys:columnAppend:delete')")
    public Result<?> deleteMatch(@Parameter(description = "账单项目字段累加配置ID，多个以英文逗号(,)分割") @PathVariable String ids) {
        boolean result = sysColumnAppendService.deleteMatch(ids);
        return Result.judge(result);
    }

    @Operation(summary = "账单项目字段累加配置数据", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/{platformKey}/form")
    public Result<?> getColumnMatchForm(@Parameter(description = "平台KEY") @PathVariable String platformKey) {
        return Result.success(sysColumnAppendService.getByPlatform(platformKey));
    }
}
